package com.skyz.wrap.utils;

import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.CompoundButton;
import android.widget.EditText;

import com.kyleduo.switchbutton.SwitchButton;

public class PassUtil {

    public static void  setEditInputType(EditText editText,int type){
        editText.setSingleLine();
        editText.setInputType(type);
    }

    /**
     * 设置数字密码-显示数字
     * @param editText
     */
    public static void setEditInputTypeNumber(EditText editText){
        setEditInputType(editText, EditorInfo.TYPE_CLASS_NUMBER|EditorInfo.TYPE_NUMBER_FLAG_SIGNED);
    }

    /**
     * 设置数字密码-不显示数据
     * @param editText
     */
    public static void setEditInputTypeNumberPass(EditText editText){
        setEditInputType(editText, EditorInfo.TYPE_CLASS_NUMBER|EditorInfo.TYPE_NUMBER_VARIATION_PASSWORD);
    }
    /**
     * 设置文字密码-不显示数据
     * @param editText
     */
    public static void setEditInputTypetextPass(EditText editText){
        setEditInputType(editText, EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_PASSWORD);
    }
    /**
     * 设置文字密码-不显示数据
     * @param editText
     */
    public static void setEditInputTypetext(EditText editText){
        setEditInputType(editText, EditorInfo.TYPE_CLASS_TEXT);
    }

    public static void setNumberEditSwichBottom(EditText editText, SwitchButton bt){
        bt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    setEditInputTypeNumber(editText);
                }else {
                    setEditInputTypeNumberPass(editText);
                }
            }
        });
    }

    public static void setNumberEditSwichBottom(EditText editText, boolean isChecked){
        if (isChecked){
            setEditInputTypeNumber(editText);
        }else {
            setEditInputTypeNumberPass(editText);
        }
    }
    public static void setTextEditSwichBottom(EditText editText, SwitchButton bt){
        bt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    setEditInputTypetext(editText);
                }else {
                    setEditInputTypetextPass(editText);
                }
            }
        });
    }

    public static void setTextEditSwichBottom(EditText editText, boolean isChecked){
        if (isChecked){
            setEditInputTypetext(editText);
        }else {
            setEditInputTypetextPass(editText);
        }
    }

    public static void setNumberEditSwichBottom(EditText editPass, View btn_see, View img_see, View img_see_o) {
        btn_see.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean checked = img_see.getVisibility() == View.VISIBLE;
                if(checked){
                    img_see.setVisibility(View.GONE);
                    img_see_o.setVisibility(View.VISIBLE);
                }else {
                    img_see.setVisibility(View.VISIBLE);
                    img_see_o.setVisibility(View.GONE);
                }
                setNumberEditSwichBottom(editPass,checked);
            }
        });
    }
    public static void setTextEditSwichBottom(EditText editPass, View btn_see, View img_see, View img_see_o) {
        btn_see.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean checked = img_see.getVisibility() == View.VISIBLE;
                if(checked){
                    img_see.setVisibility(View.GONE);
                    img_see_o.setVisibility(View.VISIBLE);
                }else {
                    img_see.setVisibility(View.VISIBLE);
                    img_see_o.setVisibility(View.GONE);
                }
                setTextEditSwichBottom(editPass,checked);
            }
        });
    }
}
